<html>

	<head>
		<meta charset="utf-8">
		<title>掌上工单</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../css/common.css" />	
		<link rel="stylesheet" href="../css/common_article.css" />
		<style>
			.title{
				background-color: rgba(0,153,204,.9);
			}
			.mui-icon{
				color: #FFFFFF;
			}
			.mui-content{
				margin-bottom: 4px;
			}
			.label{
				color: #7E7878;
			}
			.primary{
				color: #007aff;
				padding-top: 8px;
			}
			.refuse{
				margin-left: 3%;
				width: 45%;
				height: 85%;
				float: left;
				top: 0;
			}
			.accept{
				margin-right: 3%;
				width: 45%;
				height: 85%;
				float: right;
				top: 0;
			}
		</style>
	</head>
	<script id='unaccept-template' type="text/template">
		<% if(row){ %>
			<div class="mui-content-padded mui-input-group"  style="margin: 0;">
				<div style="height: auto;text-align: center; padding: 10px;">
					<label style="width: auto;font-size: 20;"><%=( row.code || '')%></label>
				</div>
				<div class="mui-input-row " style="color: #FFFFFF; background: #0099CC;">
					<label style="width: auto;">
					基本信息
					</label>
				</div>
				<div class="mui-input-row" style="height: auto;">
					<label class="label">工单编号</label>
					<label style="width: auto;"><%=( row.code || '')%></label>
				</div>
	
				<div class="mui-input-row" style="height: auto;">
					<label class="label">工单名称</label>
					<label style="width: auto;"><%=( row.name || '')%></label>
				</div>
				
				<div class="mui-input-row" style="height: auto;">
					<label class="label">工单类型 </label>
					<label style="width: auto;"><%=(row.type == 1 ? "非指定时间" :"指定时间")%></label>
				</div>
				
				<div class="mui-input-row" style="height: auto;">
					<label class="label">下发时间</label>
					<label style="width: auto;"><%=( row.createTime || '')%></label>
				</div>
				
				<div class="mui-input-row" style="height: auto;">
					<label class="label">派单人</label>
					<label style="width: auto;"><%=( row.creatorInfo.empName || '')%></label>
				</div>
				<div class="mui-input-row" style="height: auto;">
					<label class="label">联系电话</label>
					<label style="width: auto;"><%=( row.creatorInfo.tel || '')%></label>
				</div>
				<div class="mui-input-row" style="height: auto;">
					<label class="label">手机号码</label>
					<label style="width: auto;"><%=( row.creatorInfo.phone || '')%></label>
				</div>
				
				<div class="mui-input-row" style="height: auto;">
					<label class="label">任务内容</label>
					<label style="width: auto;"><%=( row.content || '无')%></label>
				</div>
				<div class="mui-input-row" style="height: auto;">
					<label class="label">附件内容</label>
					<label class="downloadFiles" style="width: auto;" >
						<% if(row.orderFiles){  
							for(var i = 0;i < row.orderFiles.length;i ++){
						%>
						<a href="javascript:void(0)" data-file="<%=row.orderFiles[i].id %>"><%=row.orderFiles[i].fileName %></a> 
						<%} 
						}%>
					</label>
				</div>
			</div>
			<div class="mui-input-row " style="color: #FFFFFF;background: #0099CC;">
				<label style="width: auto;">
				操作备注
				</label>
			</div>
			<div  class="mui-input-row" style="height: auto;">
				<div class="mui-collapse-content mui-input-group">
					<div class="mui-input-group">
						<% 
							var transfers = row.transfers;
							for(var i = 0;i < transfers.length;i ++){
								
						%>
							<div class="mui-input-row"  style="height: auto;">
								<h5 class="mui-content-padded"><%=transfers[i].operateTime || '' %></h5>
								<label style="width: auto;">【<%=transfers[i].beforLabel%> -> <%=transfers[i].afterLabel%>】 -> <%=transfers[i].des || '无' %></label>
							</div>
						<%}%>
					</div>
				</div>
			</div>
			
		<%}%>
		
	</script>
	<body>
		<header class="mui-bar mui-bar-nav title">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" style="color: #FFFFFF;">任务详情</h1>
		</header>
		<div class="mui-bar mui-bar-tab btn-detail"  id='btn-opears' style="background: rgba(0,0,0,0);-webkit-box-shadow:0 0 0px rgba(0,0,0,.85);">
			<button class="mui-btn mui-btn-block mui-btn-danger refuse" style="top: 2;">拒绝</button>
			<button class="mui-btn mui-btn-block mui-btn-primary accept" style="top: 2;">接受</button>
		</div>
		<div class="mui-content" id="task-content" >
			
		</div>
		<!--<div class="mui-content-padded " id='btn-opears' style="display: none;">
			<button class="mui-btn mui-btn-block mui-btn-primary accept" id="accept">接受</button>
			<button class="mui-btn mui-btn-block mui-btn-danger refuse">拒绝</button>
		</div>-->
	</body>
	<script src="../js/mui.min.js"></script>
	<script src="../js/mui.zoom.js"></script>
	<script src="../js/mui.previewimage.js"></script>
	<script src="../js/arttmpl.js"></script>
	<script type="text/javascript" src="../js/md5.js" ></script>
	<script type="text/javascript" src="../js/uuid.js" ></script>
	<script type="text/javascript" src="../js/utils.js" ></script>
	<script>
		
		var taskId = 0,search='';
		mui.previewImage();
		mui.plusReady(function() {
			taskId = xhz.getString("taskId") ;
			search = xhz.getString("search") ;
			xhz.ajax(EMC_URL_TASK_DETAIL,{taskId:taskId},function(data){
				if(!data || data.code != 1){
					mui.toast('你刷的太勤快了，亲');
					return ;
				}
				
				afterGotData(data.data);
			}) ;
			
			afterGotData = function(detail){
				console.debug(JSON.stringify(detail)) ;
				
				var detailInfo = template('unaccept-template', {
									"row": detail
								});
				
				document.getElementById('task-content').innerHTML = detailInfo;
				document.getElementById('btn-opears').style.display="block" ;
					mui('.downloadFiles').on('tap', 'a', function() {
					var id =  this.getAttribute('data-file');
					console.debug("========"+id) ;
					plus.runtime.openURL(EMC_DOWNLOAD_FILE+"/"+id);
				});
				
			};
			
		});
		var aniShow = "pop-in";
		var btnArray = ['取消','确认']; 
		mui(".btn-detail").on("tap",".accept",function(event){
			mui.confirm('确认接受该任务？', '', btnArray, function(e) {
				if (e.index == 1) {//确定
					plus.nativeUI.showWaiting("正在处理");
					xhz.ajax(EMC_URL_TASK_ACCEPT,{taskId:taskId},function(data){
						plus.nativeUI.closeWaiting();
						if(data && data.code == 1){
							document.getElementById('btn-opears').style.display="none" ;
							mui.toast("任务领取成功") ;
							 
//							var lastPage = plus.webview.getWebviewById('emc-sub-home');
//							mui.fire(lastPage, "taskinfo:remove",{id:'node_'+taskId});
							var lastPage = plus.webview.getWebviewById('emc-task-search');
							mui.fire(lastPage, "taskinfo:removed",{id:'node_'+taskId});
							mui.back() ;
							return ;
						}
						mui.toast(data.message) ;
					},function(){
						
					})
				}
			});
		});
		
		mui(".btn-detail").on("tap",".refuse",function(event){
  			var href = 'task-refuse.html';
			var webview_style = {
				popGesture: "close"
			};
			mui.openWindow({
				id: 'task-refuse',
				url: href,
				styles: webview_style,
				show: {
					aniShow: aniShow
				},
				waiting: {
					autoShow: true
				},
				extras:{
			    	taskId:taskId,
			    	search:search
			    }
			});
//			mui.later(function() {
//				var cview = plus.webview.currentWebview();
//				cview.close() ;
//			}, 500);
		});
		//重写返回方法
//		mui.back = function(){
//			mui.currentWebview.close();//返回关闭当前页面
//		}
//		callback = function(e){
//			console.debug("unaccept:back") ;
//			var cview = plus.webview.currentWebview();
//			cview.close() ;
//			mui.currentWebview.close();//返回关闭当前页面
//		}
//		window.addEventListener("unaccept:close", callback);

			window.addEventListener("page:close", function(){
				var cview = plus.webview.currentWebview();
				cview.close() ;
			});
	</script>

</html>